import express from'express';
import jwt from'jsonwebtoken';
import * as dotenv from 'dotenv';
dotenv.config({
    path:['.env.local','env'],
});
const app=express()
const port=3000
function authKlingai(){
    const headers={
        algorithm:'HS256',
    }
    const now=Math.floor(Date.now()/1000);
    const payload={
        iss:process.env.ACCESS_KEY_ID,
        exp:now+1800,
        nbf:now-5,
     }
     //用keling的密钥生成一个令牌
     const token=jwt.sign(payload,process.env.ACCESS_KEY_SECRET,headers)
     return token;
}
app.get('/jwt-auth',async(req,res)=>{
  const token=await authKlingai();
  res.send(token)

})
app.listen(port,()=>{
  console.log(`Example app listening at http://localhost:${port}`)
})